#include "VJsonSettingDilg.h"
#include "ui_VJsonSettingDilg.h"
#include "VJsonItemWidget.h"

#include <QLayout>
#include <QDebug>

VJsonSettingDilg::VJsonSettingDilg(QWidget *parent) :
    QDialog(parent),
    ui(new Ui::VJsonSettingDilg)
{
    ui->setupUi(this);

    m_layout = new QVBoxLayout(ui->widget);


//    m_layout->addWidget(new VJsonItemWidget(nullptr, "font", "字体", "100"));
//    m_layout->addWidget(new VJsonItemWidget(nullptr, "i", "字体大小", "16"));
//    m_layout->addWidget(new VJsonItemWidget(nullptr, "b", "粗体", "true"));
//    m_layout->addWidget(new VJsonItemWidget(nullptr, "b", "斜体", "true"));
//    m_layout->addWidget(new VJsonItemWidget(nullptr, "c", "颜色", "FF00FF"));
//    m_layout->addWidget(new VJsonItemWidget(nullptr, "c", "颜色", "FF00FF"));
//    m_layout->addWidget(new VJsonItemWidget(nullptr, "c", "颜色", "FF00FF"));
//    m_layout->addWidget(new VJsonItemWidget(nullptr, "c", "颜色", "FF00FF"));
//    m_layout->addWidget(new VJsonItemWidget(nullptr, "c", "颜色", "FF00FF"));
//    m_layout->addWidget(new VJsonItemWidget(nullptr, "c", "颜色", "FF00FF"));
}

VJsonSettingDilg::~VJsonSettingDilg()
{
    delete ui;
}

void VJsonSettingDilg::add_item(QString type, QString key, QString value)
{
    auto item = new VJsonItemWidget(nullptr, type, key, value);
    item->setObjectName(key);
    m_layout->addWidget(item);
}

QString VJsonSettingDilg::get_item_value(QString key, bool &isOk)
{
    auto ptr = this->findChild<VJsonItemWidget*>(key);

    if(ptr == nullptr)
    {
        isOk = false;
//        qDebug() << "isOk:" << isOk;
        return "";
    }

//    qDebug() << "object name";
//    qDebug() << ptr->objectName();
//    qDebug() << "isOk:" << isOk;
    isOk = true;
    return ptr->get_value();
}
